package com.wmeimob.fastboot.jiubei.service;

import com.wmeimob.fastboot.jiubei.entity.ShopOrderItems;
import com.wmeimob.fastboot.jiubei.mapper.ShopOrderItemsMapper;
import com.wmeimob.fastboot.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @version 1.0
 * @ClassName ShopOrderItemsServiceImpl
 * @Description 订单明细 服务类实现
 * @Author wjt
 * @Date Mon Aug 31 23:57:11 CST 2020
 **/

@Service
@Transactional(rollbackFor = {Exception.class})
@Slf4j
public class ShopOrderItemsServiceImpl implements ShopOrderItemsService {

    @Resource
    private ShopOrderItemsMapper shopOrderItemsMapper;


    @Override
    public List<ShopOrderItems> list(ShopOrderItems shopOrderItems) {
        Example example = new Example(ShopOrderItems.class);
        Example.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(shopOrderItems.getId())) {
            criteria.andEqualTo("id", shopOrderItems.getId());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getOrderId())) {
            criteria.andEqualTo("orderId", shopOrderItems.getOrderId());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getOrderNo())) {
            criteria.andLike("orderNo", StringUtils.fullFuzzy(shopOrderItems.getOrderNo()));
        }
        if (!StringUtils.isEmpty(shopOrderItems.getGoodsId())) {
            criteria.andEqualTo("goodsId", shopOrderItems.getGoodsId());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getGoodsName())) {
            criteria.andLike("goodsName", StringUtils.fullFuzzy(shopOrderItems.getGoodsName()));
        }
        if (!StringUtils.isEmpty(shopOrderItems.getGoodsSkuNo())) {
            criteria.andLike("goodsSkuNo", StringUtils.fullFuzzy(shopOrderItems.getGoodsSkuNo()));
        }
        if (!StringUtils.isEmpty(shopOrderItems.getGoodsSkuName())) {
            criteria.andLike("goodsSkuName", StringUtils.fullFuzzy(shopOrderItems.getGoodsSkuName()));
        }
        if (!StringUtils.isEmpty(shopOrderItems.getSalePrice())) {
            criteria.andEqualTo("salePrice", shopOrderItems.getSalePrice());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getSaleQuantity())) {
            criteria.andEqualTo("saleQuantity", shopOrderItems.getSaleQuantity());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getShippingFee())) {
            criteria.andEqualTo("shippingFee", shopOrderItems.getShippingFee());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getItemsAmount())) {
            criteria.andEqualTo("itemsAmount", shopOrderItems.getItemsAmount());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getItemsShippingDeduction())) {
            criteria.andEqualTo("itemsShippingDeduction", shopOrderItems.getItemsShippingDeduction());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getItemsPayAmount())) {
            criteria.andEqualTo("itemsPayAmount", shopOrderItems.getItemsPayAmount());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getRefundStatus())) {
            criteria.andLike("refundStatus", StringUtils.fullFuzzy(shopOrderItems.getRefundStatus()));
        }
        if (!StringUtils.isEmpty(shopOrderItems.getGmtCreate())) {
            criteria.andEqualTo("gmtCreate", shopOrderItems.getGmtCreate());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getGmtModified())) {
            criteria.andEqualTo("gmtModified", shopOrderItems.getGmtModified());
        }
        if (!StringUtils.isEmpty(shopOrderItems.getGoodsNo())) {
            criteria.andLike("goodsNo", StringUtils.fullFuzzy(shopOrderItems.getGoodsNo()));
        }
        example.orderBy("id").desc();
        List<ShopOrderItems> shopOrderItemss = shopOrderItemsMapper.selectByExample(example);
        return shopOrderItemss;
    }

    @Override
    public ShopOrderItems queryShopOrderItemsById(Long id) {
        return shopOrderItemsMapper.selectByPrimaryKey(id);
    }


    @Override
    public void addShopOrderItems(ShopOrderItems shopOrderItems) {
        shopOrderItems.setGmtCreate(new Date());
        shopOrderItemsMapper.insertSelective(shopOrderItems);
    }

    @Override
    public void removeShopOrderItems(Long id) {
        ShopOrderItems shopOrderItems = new ShopOrderItems();
        shopOrderItems.setId(id);
        shopOrderItemsMapper.updateByPrimaryKeySelective(shopOrderItems);
    }

    @Override
    public void modifyShopOrderItems(ShopOrderItems shopOrderItems) {
        shopOrderItems.setGmtModified(new Date());
        shopOrderItemsMapper.updateByPrimaryKeySelective(shopOrderItems);
    }

}
